<!DOCTYPE html>
<html>
<head>
<#include "/admin/common/common.ftl" parse=true encoding="utf-8">
<link href="${base}/scripts/ckeditor/skins/moono/editor.css" type="text/css" rel="stylesheet">
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">

		<#include "/admin/common/header.ftl" parse=true encoding="utf-8">

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>模板管理</h1>
				<ol class="breadcrumb">
					<li class="active">添加邮件模板</li>
				</ol>
			</section>

			<!-- Main content -->
			<section class="content">
				<!-- Info boxes -->
				<div class="row">
					<div class="box">
						<div class="box-header">
							<div class="table-btn">
								<a href="${base}/admin/template/mail/list.do">
									<span class="label label-primary">列表</span>
								</a>
							</div>
						</div>
						<!-- /.box-header -->
						<div class="box-body">
							<h3 id="affix-events">添加新的邮件模板</h3>
							<form class="form-horizontal" role="form" name="defaultForm" id="defaultForm" method="post" action="#">
								<div class="form-group">
									<label class="col-md-2 control-label">模板类型</label>
									<div class="col-md-8">
										<select id="type" name="type">
											<option value="1">邮箱验证模板</option>
											<option value="2">验证码模板</option>
											<option value="3">找回密码模板</option>
											<option value="4">修改密码模板</option>
											<option value="5">修改邮箱模板</option>
											<option value="6">警告邮件模板</option>
											<option value="99">其他模板</option>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">模板名称</label>
									<div class="col-md-8">
										<input id="name" name="name" class="form-control" type="text" rows="10" placeholder="请输入模板名称">
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">模板描述</label>
									<div class="col-md-8">
										<textarea class="form-control" rows="8" id="describe" placeholder="请输入模板描述" name="describe"></textarea>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">默认模板</label>
									<div class="col-md-8">
										<input type="radio" name="isDefault" value="true" checked="checked">
										是
										<input type="radio" name="isDefault" value="false">
										否
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">邮件主题</label>
									<div class="col-md-8">
										<input id="subject" name="subject" class="form-control" type="text" rows="10" placeholder="请输入邮件主题">
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">邮件内容</label>
									<div class="col-md-8">
										<textarea class="form-control" rows="8" id="content" placeholder="请输入模板内容" name="content"></textarea>
									</div>
								</div>
								<div class="form-group">
									<div class="col-sm-offset-3 col-sm-3">
										<button type="submit" class="btn btn-primary">添加</button>
										<button type="submit" class="btn btn-primary" onclick="returnList();">返回</button>
									</div>
								</div>
							</form>
						</div>
						<!-- /.box-body -->
					</div>
					<!-- /.box -->
				</div>
				<!-- /.row -->
			</section>
			<!-- /.content -->
		</div>
		<!-- /.content-wrapper -->

	</div>
	<!-- ./wrapper -->
	<#include "/admin/common/footer.ftl" parse=true encoding="utf-8">
</body>
<script src="${base}/scripts/ckeditor/ckeditor.js"></script>
<script src="${base}/scripts/ckeditor/config.js"></script>
<script src="${base}/scripts/ckeditor/styles.js"></script>
<script src="${base}/scripts/ckeditor/lang/zh-cn.js"></script>
<script type="text/javascript">
	function returnList(){
		window.location.href = "${base}/admin/template/mail/list.do";
	}

		$(function() {
			var contentEditor = null;
			contentEditor = CKEDITOR.replace('content');
			$('#defaultForm')
					.bootstrapValidator(
							{
								message : '该项不能为空',
								live : 'disabled',
								feedbackIcons : {
									valid : 'glyphicon glyphicon-ok',
									invalid : 'glyphicon glyphicon-remove',
									validating : 'glyphicon glyphicon-refresh'
								},
								submitHandler : function(validator, form,
										submitButton) {
									if (window.confirm("确定要添加该邮件模板？")) {
										contentEditor.updateElement();
										var url = "${base}/admin/template/mail/addnewAction.json";
										var entity = {
												type: $("#type").val(),
											 	name: $("#name").val(),
												describe:$("#describe").val(),
												isDefault:$("input[name='isDefault']:checked").val(),
												subject:$("#subject").val(),
												content:$("#content").val()
										};
										var onloadFunc = function(result) {
											if (result.isSuccess == true) {
												alert('添加成功');
												window.location = "${base}/admin/template/mail/list.do";
											} else {
												alert(result.message);
											}
										};
										httpRequestPostJson(url, entity, false,
												onloadFunc);
									} else {
										return;
									}
								},
								fields : {
									name : {
										validators : {
											notEmpty : {
												message : '模板名称不能为空'
											}
										}
									},
									describe : {
										validators : {
											notEmpty : {
												message : '模板描述不能为空'
											}
										}
									},
									content : {
										validators : {
											notEmpty : {
												message : '模板内容不能为空'
											}
										}
									}
								}
							});
		});
	</script>
</html>